//*************************************************************************
// Account2.java   Author:20172330
//
// 编写一个处理30人信息的类，
//*************************************************************************
public class Account2
{
    private Account1[] people;
    private int count, number = 0;
    //编写一个30用户的数组
    public Account2()
    {
        people = new Account1[30];
        count = 0;
    }
   
    //每一个数组对象中所包含的信息
    public void AddAccount(String name, long acctNumber, double balance)
    {
        people[count] = new Account1(name, acctNumber, balance);
        count++;
    }

    //判断输入的用户是否在可视范围内，若可视则进行存款并且显示其账户内信息。
    public String setSave(String owner, long account, double savemoney)
    {
        double balance;
        if (number < 0 && number > 30)
            return "抱歉，你输入的内容错误，该账户不在管理范围";
        else
            people[number].deposit(savemoney);
        balance = people[number].getBalance();

        return "你给第" + (1 + number) + "位账户存了" + savemoney +
                "该账户余额为：" + balance;
    }
    //判断输入的用户是否在可视范围内，若可视则进行取款服务
    public String setDraw(String owner, long account, double getmoney)
     {
        {if (number < 0 && number > 30)
            return "抱歉，你输入的内容错误，该账户不在管理范围.";
        //若账户余额不足则显示，若余额足够则进行取款服务并显示余额
        
         else if (getmoney > people[number].getBalance())
            return "错误，第"+(number+1)+"用户您的余额已不足.";
         else
              people[number].withdraw(getmoney);
        }return "您从第" + (1 + number) + "位账户取出" + getmoney +
                "该账户余额为：" + people[number].getBalance();
    }
    
    //对银行账户内的存款进行加利息运算
    public void addInterest()
    {
        for (int n = 0; n < people.length; n++)
        {
          if (people[n] != null)      
          people[n].addInterest();
        }
    }
    //定义toString方法，使得在账户进行操作之后显示用户信息。
    public String toString()
    {
        String information = "用户账户详情\n";
        for (int a = 0; a <= count; a++)
        {
            if (people[a] != null)
                information += people[a].toString() + "\n";
        }
        return information;
    }

}

